package com.music.controller;

import com.music.pojo.Subscribe;
import com.music.service.SubscribeService;

import com.laoxuai.beans.annotation.Autowired;
import com.laoxuai.beans.annotation.Controller;
import com.laoxuai.ibatis.util.PageInfo;
import com.laoxuai.web.mvc.annotation.RequestMapping;
import com.laoxuai.web.mvc.annotation.ResponseBody;
import com.music.pojo.Subscribe;
import com.music.service.SubscribeService;
import com.music.util.Result;

import java.util.List;

@Controller
@RequestMapping("/subscribe")
public class SubscribeController {

    @Autowired
    private SubscribeService subscribeServiceImpl;

    /**
     * 新增
     * @param userId
     * @param playlistId
     * @return
     */
    @RequestMapping("/insert")
    @ResponseBody
    public Result insert(Integer userId,Integer playlistId) {
        int result = subscribeServiceImpl.insert(userId,playlistId);
        if(result==-1){
            return Result.failed("您已收藏过该歌单！");
        }
        return Result.success("收藏成功", result);
    }

    /***
     * 删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Result delete(Integer id) {
        int result = subscribeServiceImpl.delete(id);
        return Result.success("删除成功", result);
    }

    /***
     * 修改
     * @param subscribe
     * @param id
     * @return
     */
    @RequestMapping(value="/update")
    @ResponseBody
    public Result update(Integer id, Subscribe subscribe) {
        subscribe.setId(id);
        int result = subscribeServiceImpl.update(subscribe);
        return Result.success("修改成功");
    }

    /***
     * 主键查询
     * @param id
     * @return
     */
    @RequestMapping("/get")
    @ResponseBody
    public Result getByPrimaryKey(Integer id) {
        Subscribe subscribe = subscribeServiceImpl.getByPrimaryKey(id);
        return Result.success("查询成功", subscribe);
    }

    @RequestMapping(value = "/page")
    @ResponseBody
    public Result page(Subscribe subscribe, int page, int size) {
        PageInfo<Subscribe> pageInfo = subscribeServiceImpl.listPageInfo(subscribe, page, size);
        return Result.success("查询成功", pageInfo);
    }

    @RequestMapping(value = "/list")
    @ResponseBody
    public Result list(Subscribe subscribe, int page, int size) {
        List<Subscribe> list = subscribeServiceImpl.listPage(subscribe, page, size);
        return Result.success("查询成功", list);
    }
}